package com.hippo.javacore.multithreading;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @ClassName ThreadDemo15
 * @Description TODO 线程池--使用工具类创建线程池
 * @Author tangxl
 * @create 2023-03-16 15:26
 **/
public class ThreadDemo15 {
    public static void main(String[] args) {
        // 创建一个没有上线的线程池
        //         ExecutorService pool = Executors.newCachedThreadPool();
        // 创建一个有上线的线程池
        ExecutorService pool = Executors.newFixedThreadPool(5);
        // 创建10个任务
        for (int i = 0; i < 10; i++) {
            // 给线程池提交任务
            pool.submit(new Runnable() {
                 @Override
                 public void run() {
                     System.out.println(Thread.currentThread().getName());
                 }
            });
        }
        // 查看线程池中线程数量
        pool.shutdown();
        // 关闭线程池
        pool.shutdown();
    }
}
